package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Guanxing
 * @date 2021/9/18
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //添加用户,返回主键
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    //根据手机号查询用户
    @Override
    public User findByPhone(String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        return userMapper.selectOne(queryWrapper);
    }

    //修改手机号 - 3 保存
    @Override
    public void updatePhone(User user) {
        userMapper.updateById(user);
    }
}
